<template>
    <div class="chat-input-container">
      <div class="input-wrapper">
        <el-input
          v-model="imInput"
          class="chat-input"
          placeholder="请输入消息..."
          :disabled="disabled"
          @keyup.enter="handleSend"
          resize="none"
          :rows="2"
          type="textarea"
          :autosize="{ minRows: 1, maxRows: 6 }"
        />
      </div>
      <div class="action-buttons">
        <el-button
          type="primary"
          class="send-button"
          :loading="sending"
          :disabled="!canSend"
          @click="handleSend"
        >
          <template #icon>
            <el-icon><Promotion /></el-icon>
          </template>
          发送
        </el-button>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref, computed } from 'vue'
  import { Promotion } from '@element-plus/icons-vue'
  
  const props = defineProps({
    // 是否禁用输入框
    disabled: {
      type: Boolean,
      default: false
    },
    // 发送状态，由父组件控制
    sending: {
      type: Boolean,
      default: false
    }
  })
  
  const emit = defineEmits(['send'])
  
  const imInput = ref('')
  
  // 计算属性，判断是否可以发送消息
  const canSend = computed(() => {
    return !props.disabled && !props.sending && imInput.value.trim().length > 0
  })
  
  // 处理发送消息
  const handleSend = () => {
    if (!canSend.value) return
    
    const message = imInput.value.trim()
    if (!message) return
    
    emit('send', message)
    imInput.value = ''
  }
  </script>
  
  <style scoped>
  .chat-input-container {
    display: flex;
    gap: 12px;
    padding: 16px;
    background-color: #f9f9f9;
    border-top: 1px solid #eaeaea;
    position: sticky;
    bottom: 0;
  }
  
  .input-wrapper {
    flex: 1;
    min-width: 0;
  }
  
  .chat-input {
    width: 100%;
  }
  
  .chat-input :deep(.el-textarea__inner) {
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.5;
    min-height: 40px;
    max-height: 120px;
    resize: none;
  }
  
  .action-buttons {
    display: flex;
    align-items: flex-end;
    gap: 8px;
  }
  
  .send-button {
    height: 40px;
    padding: 0 20px;
    border-radius: 8px;
  }
  
  /* 响应式调整 */
  @media (max-width: 768px) {
    .chat-input-container {
      flex-direction: column;
    }
    
    .action-buttons {
      align-items: flex-start;
      width: 100%;
    }
    
    .send-button {
      width: 100%;
    }
  }
  </style>